//
//  LGTeamDetailContentView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/16.
//  团队详情-团队名称、介绍、咨询

#import "LGTeamDetailContentView.h"

@interface LGTeamDetailContentView()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**  团队名称 */
@property (nonatomic , strong)UILabel *nameTitle;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UIImageView *nameTip;

/**  团队介绍 */
@property (nonatomic , strong)UILabel *contentTitle;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UIImageView *contenTip;

/**  团队咨询 */
//@property (nonatomic , strong)UILabel *consultTitle;
///**   */
//@property (nonatomic , strong)UILabel *consultLabel;
///**   */
//@property (nonatomic , strong)UIImageView *consultTip;

@end

@implementation LGTeamDetailContentView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSInteger length = isPad?30:12;
    NSString *title = [dataDic[@"title"] length]>length?[NSString stringWithFormat:@"%@...",[dataDic[@"title"] substringToIndex:length]]:dataDic[@"title"];
    self.nameLabel.text = (title.length>0)?title:@" ";
    NSString *content = LGNSString(dataDic[@"desc"]);
    self.contentLabel.text = content;
//    self.consultLabel.text = LGNSString(dataDic[@"services"]);
    [self performSelector:@selector(reloadSubViews) withObject:nil afterDelay:0.1];
}


-(void)setCanEdit:(BOOL)canEdit{
    _canEdit = canEdit;
    if(canEdit == NO){
        [self.nameTip mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(0.01));
        }];
//        [self.consultTip mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.width.equalTo(@(0.01));
//        }];
        
    }else{
        [self.nameTip mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(viewPix(16)));
        }];
//        [self.consultTip mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.width.equalTo(@(viewPix(16)));
//        }];
    }
}

-(void)reloadSubViews{
    [self.nameLabel sizeToFit];
    [self.contentLabel sizeToFit];
    CGFloat height = kMaxY(self.contentLabel.frame)+viewPix(16);
    if(self.delegate && [self.delegate respondsToSelector:@selector(contentViewHeight:)]){
        [self.delegate contentViewHeight:height];//kMaxY(self.openBtn.frame)+viewPix(35)
    }
}

//点击手势
-(void)editTeamContentAction:(UITapGestureRecognizer *)sender{
    CGFloat point_Y = [sender locationInView:self].y;
    NSString *type = @"";
    NSString *content = @"";
    if(point_Y<kMaxY(self.contentTitle.frame)){
        //名称
        if (self.canEdit == NO) return;
        type = @"title";
        content = self.dataDic[@"title"];
        
    }else if (point_Y<kMaxY(self.contentLabel.frame)){
        //介绍
        type = @"desc";
        content = self.contentLabel.text;
        
    }else{
        //咨询
        if (self.canEdit == NO) return;
        type = @"consult";
        content = LGNSString(self.dataDic[@"teamid"]);
    }
    if(self.delegate && [self.delegate respondsToSelector:@selector(editTeamContent:content:)]){
        [self.delegate editTeamContent:type content:content];
    }
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(editTeamContentAction:)]];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.nameTitle];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.nameTip];
    [self.baseView addSubview:self.contentTitle];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView addSubview:self.contenTip];

//    [self.baseView addSubview:self.consultTitle];
//    [self.baseView addSubview:self.consultLabel];
//    [self.baseView addSubview:self.consultTip];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self);
    }];
    [self.nameTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.baseView).offset(viewPix(16));
        make.width.equalTo(@(viewPix(70)+iPadMargin(50)));
//        make.height.equalTo(@(viewPix(23)));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.nameTitle.mas_right).offset(viewPix(10));
        make.right.equalTo(self.nameTip.mas_left).offset(-2);
//        make.width.equalTo(@(viewPix(170)));
        make.top.equalTo(self.nameTitle);
    }];
    [self.nameTip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(16));
        make.width.height.equalTo(@(viewPix(16)));
        make.centerY.equalTo(self.nameTitle);
    }];
    
    [self.contentTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(16));
        make.left.right.equalTo(self.nameTitle);
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentTitle.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.contentTitle);
        make.right.equalTo(self.contenTip.mas_left).offset(-viewPix(5));
    }];
    
    [self.contenTip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel).offset(viewPix(2));
        make.width.height.equalTo(@(viewPix(16)));
        make.right.equalTo(self.nameTip);
    }];
    
//    [self.consultTitle mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.contentLabel.mas_bottom).offset(viewPix(16));
//        make.left.right.height.equalTo(self.nameTitle);
//    }];
//    [self.consultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.consultTitle.mas_right).offset(viewPix(10));
//        make.right.equalTo(self.consultTip.mas_left).offset(-2);
//        make.centerY.equalTo(self.consultTitle);
//    }];
//    [self.consultTip mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.baseView).offset(-viewPix(16));
//        make.width.height.equalTo(@(viewPix(16)));
//        make.centerY.equalTo(self.consultTitle);
//    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.clipsToBounds = YES;
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UILabel *)nameTitle{
    if(!_nameTitle){
        _nameTitle = [UILabel lableWithText:@"团队名称" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameTitle;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@" " colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentRight lines:2];
    }
    return _nameLabel;
}

-(UIImageView *)nameTip{
    if(!_nameTip){
        _nameTip = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
    }
    return _nameTip;
}

-(UILabel *)contentTitle{
    if(!_contentTitle){
        _contentTitle = [UILabel lableWithText:@"团队介绍" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _contentTitle;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:3];
        [_contentLabel sizeToFit];
    }
    return _contentLabel;
}

-(UIImageView *)contenTip{
    if(!_contenTip){
        _contenTip = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
    }
    return _contenTip;
}

//-(UILabel *)consultTitle{
//    if(!_consultTitle){
//        _consultTitle = [UILabel lableWithText:@"团队咨询" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
//    }
//    return _consultTitle;
//}
//
//-(UILabel *)consultLabel{
//    if(!_consultLabel){
//        _consultLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentRight lines:1];
//    }
//    return _consultLabel;
//}
//
//-(UIImageView *)consultTip{
//    if(!_consultTip){
//        _consultTip = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
//    }
//    return _consultTip;
//}

@end
